package com.itrip.service.impl;

import com.itrip.dao.ex.HotelMapperEX;
import com.itrip.document.Hotel;
import com.itrip.dto.HotelRoomDTO;
import com.itrip.repository.HotelRepository;
import com.itrip.service.HotelService;
import com.itrip.vo.hotel.HotelVO;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@Service
public class HotelServiceImpl implements HotelService {
    @Resource
    private HotelRepository hotelRepository;


    @Resource
    private HotelMapperEX hotelMapperEX;

    @Cacheable(value = "hotel", key = "'getHotelByQuery'+#keyword+','+#pageNow+','+#pageSize")

    /**
     *
     * @param keyword  关键词
     * @param pageNow  页码
     * @param pageSize  显示行数
     * @return
     * @throws IOException
     * @throws SolrServerException
     */
    @Override

    public List<Hotel> getHotelByQuery(HotelVO hotelVO, Integer pageNow, Integer pageSize) throws IOException, SolrServerException {
        return hotelRepository.getHotelByQuery(hotelVO,(pageNow-1)*pageSize, pageSize);
    }

    @Override
    public long getHotelCount(HotelVO hotelVO) throws IOException, SolrServerException {
        return hotelRepository.getHotelCount(hotelVO);
    }

    @Cacheable(value = "hotelRoom", key = "'getHotelRoomList'+#id")
    @Override
    public HotelRoomDTO getHotelRoomList(Integer id) {
        return hotelMapperEX.getHotelRoomList(id);
    }

    @Override
    public List<HotelRoomDTO> getQueryHotelRoomList(String hotelName) {
        return hotelMapperEX.getQueryHotelRoomList(hotelName);
    }
}
